package com.ims.task;

import com.ims.common.utils.DateUtils;
import com.ims.core.doc.service.ITInInvoiceService;
import com.ims.core.erp.ErpApiUtil;
import com.ims.core.inconfig.service.ITSrmSupplierService;
import com.ims.core.saleconfig.service.ITSalBuyerService;
import com.ims.core.saleconfig.service.ITSalMaterialService;
import com.ims.system.service.ISysDictDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 百望数据同步 task任务
 */
@Component("BaiwangDataTask")
public class BaiwangDataTask {
    //日志
    private static final Logger logger = LoggerFactory.getLogger(BaiwangDataTask.class);

    @Autowired
    private ITInInvoiceService inInvoiceService;

    /**
     * 进项-可抵扣发票获取和确认
     * 每天0点同步
     */
    // @Scheduled(cron = "0 0/3 * * * ?")
    public void inIinvoiceDataSync() {
        // cron : 0 */1 * * * ?
        logger.info("---inIinvoiceDataSync task------produce Data with fixed rate task: Execution Time - {}", DateUtils.getNowDate());
        try {
            inInvoiceService.invoiceDeductionDataSyncFromBaiwang();
            logger.info("---inIinvoiceDataSync task------produce Data with fixed rate task: END Time - {}", DateUtils.getNowDate());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("inIinvoiceDataSync.task" + " | msg : " + e.getMessage());
        }
    }

    /**
     * 未获取完整信息的进项发票，同步完整信息
     * 每天0点同步
     */
    // @Scheduled(cron = "0 0/2 * * * ?")
    public void inIinvoiceDetailDataSync() {
        // cron : 0 */1 * * * ?
        logger.info("---inIinvoiceDetailDataSync task------produce Data with fixed rate task: Execution Time - {}", DateUtils.getNowDate());
        try {
            inInvoiceService.inIinvoiceDetailDataSyncFromBaiwang();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("inIinvoiceDetailDataSync.task" + " | msg : " + e.getMessage());
        }
    }

    /**
     * 历史发票的信息同步
     * 每天0点同步
     */
    // @Scheduled(cron = "0 0/2 * * * ?")
    public void invoiceHistoryDataSync() {
        // cron : 0 */1 * * * ?
        logger.info("---invoiceHistoryDataSync task------produce Data with fixed rate task: Execution Time - {}", DateUtils.getNowDate());
        try {
            inInvoiceService.invoiceHistoryDataSyncFromBaiwang();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("invoiceHistoryDataSync.task" + " | msg : " + e.getMessage());
        }
    }


    /**
     * 进项-历史发票同步
     * 每天0点同步
     */
    // @Scheduled(cron = "0 0/3 * * * ?")
    public void inIinvoiceHisDataSync(Integer month) {
        // cron : 0 */1 * * * ?
        logger.info("---inIinvoiceHisDataSync task------produce Data with fixed rate task: Execution Time - {}", DateUtils.getNowDate());
        try {
            // FIXME 从系统配置获取
            if(month == null){
                month = 6;
            }
            inInvoiceService.inIinvoiceHisDataSyncFromBaiwang(month);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("inIinvoiceHisDataSync.task" + " | msg : " + e.getMessage());
        }
    }


}
